﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ProjectMeeting.cs" company="DissingNelleman">
//   
// All rights reserved. </copyright>
// <summary>
//   The project meeting.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace ServiceLibrary.Services.Dto
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;

    /// <summary>
    /// The project meeting.
    /// </summary>
    [DataContract]
    public class ProjectMeeting
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the date.
        /// </summary>
        [DataMember]
        public DateTime? Date { get; set; }

        /// <summary>
        /// Gets or sets the groups.
        /// </summary>
        [DataMember]
        public List<Guid> Groups { get; set; }

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        [DataMember]
        public Guid ID { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether is national.
        /// </summary>
        [DataMember]
        public bool IsNational { get; set; }

        /// <summary>
        /// Gets or sets the location id.
        /// </summary>
        [DataMember]
        public Guid LocationID { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        [DataMember]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the owner id.
        /// </summary>
        [DataMember]
        public Guid OwnerID { get; set; }

        /// <summary>
        /// Gets or sets the owner projects.
        /// </summary>
        [DataMember]
        public List<Guid> OwnerProjects { get; set; }

        /// <summary>
        /// Gets or sets the participants.
        /// </summary>
        [DataMember]
        public List<Guid> Participants { get; set; }

        /// <summary>
        /// Gets or sets the status.
        /// </summary>
        [DataMember]
        public ProjectMeetingStatus Status { get; set; }



        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The convert.
        /// </summary>
        /// <param name="domainObject">
        /// The domain object.
        /// </param>
        /// <returns>
        /// The <see cref="ProjectMeeting"/>.
        /// </returns>
        public static ProjectMeeting Convert(Models.Domain.ProjectMeeting domainObject)
        {
            if (domainObject != null)
            {
                var dto = new ProjectMeeting
                              {
                                  ID = domainObject.ID, 
                                  Name = domainObject.Name,
                                  Date = domainObject.TimeOfActivity, 
                                  IsNational = domainObject.IsNational, 
                                  LocationID =
                                      domainObject.Location != null
                                           ? domainObject.Location.ID
                                           : Guid.Empty, 
                                  OwnerID =
                                      domainObject.Owner != null ? domainObject.Owner.ID : Guid.Empty, 
                                  Status = ProjectMeetingStatus.Convert(domainObject.Status)
                              };

                if (domainObject.OwnerProjects != null && domainObject.OwnerProjects.Any())
                {
                    dto.OwnerProjects = new List<Guid>();
                    foreach (Models.Domain.Project proj in domainObject.OwnerProjects)
                    {
                        dto.OwnerProjects.Add(proj.ID);
                    }
                }

                if (domainObject.Groups != null && domainObject.Groups.Any())
                {
                    dto.Groups = domainObject.Groups.Select(x => x.ID).ToList();
                }

                if (domainObject.Participants != null && domainObject.Participants.Any())
                {
                    dto.Participants = new List<Guid>();
                    foreach (Models.Domain.Profile prof in domainObject.Participants)
                    {
                        dto.Participants.Add(prof.ID);
                    }
                }

                return dto;
            }
            
            return null;
        }

        #endregion
    }

    /// <summary>
    /// The project meeting status.
    /// </summary>
    [DataContract]
    public class ProjectMeetingStatus
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the application about.
        /// </summary>
        [DataMember]
        public List<Guid> ApplicationAbout { get; set; }

        /// <summary>
        /// Gets or sets the application about text.
        /// </summary>
        [DataMember]
        public string ApplicationAboutText { get; set; }

        /// <summary>
        /// Gets or sets the demonstration i ds.
        /// </summary>
        [DataMember]
        public List<Guid> DemonstrationIDs { get; set; }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        [DataMember]
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets the financing.
        /// </summary>
        [DataMember]
        public List<Guid> Financing { get; set; }

        /// <summary>
        /// Gets or sets the financing text.
        /// </summary>
        [DataMember]
        public string FinancingText { get; set; }

        /// <summary>
        /// Gets or sets the guidance about.
        /// </summary>
        [DataMember]
        public List<Guid> GuidanceAbout { get; set; }

        /// <summary>
        /// Gets or sets the guidance about text.
        /// </summary>
        [DataMember]
        public string GuidanceAboutText { get; set; }

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        [DataMember]
        public Guid ID { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether is external.
        /// </summary>
        [DataMember]
        public bool IsExternal { get; set; }

        /// <summary>
        /// Gets or sets the patent name.
        /// </summary>
        [DataMember]
        public string PatentName { get; set; }

        /// <summary>
        /// Gets or sets the roles.
        /// </summary>
        [DataMember]
        public List<Guid> Roles { get; set; }

        /// <summary>
        /// Gets or sets the status of project.
        /// </summary>
        [DataMember]
        public string StatusOfProject { get; set; }

        /// <summary>
        /// Gets or sets the type.
        /// </summary>
        [DataMember]
        public Guid Type { get; set; }
        
        /// <summary>
        /// Gets or sets the status.
        /// </summary>
        [DataMember]
        public Enums.ProjectMeetingStatusType StatusType { get; set; }
        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The convert.
        /// </summary>
        /// <param name="domainObject">
        /// The domain object.
        /// </param>
        /// <returns>
        /// The <see cref="ProjectMeetingStatus"/>.
        /// </returns>
        public static ProjectMeetingStatus Convert(Models.Domain.ProjectMeetingStatus domainObject)
        {
            if (domainObject != null)
            {
                var dto = new ProjectMeetingStatus
                              {
                                  ID = domainObject.ID,
                                  PatentName = domainObject.PatentName,
                                  Description = domainObject.Description,
                                  FinancingText = domainObject.FinancingText,
                                  GuidanceAboutText = domainObject.GuidanceAboutText,
                                  IsExternal = domainObject.IsExternal,
                                  StatusOfProject = domainObject.StatusOfProject,
                                  Type = (domainObject.Type ?? new Models.Domain.ProjectType() { ID = Guid.Empty}).ID,
                                  StatusType = domainObject.StatusType
                              };
                if (domainObject.Demonstrations != null && domainObject.Demonstrations.Any())
                {
                    dto.DemonstrationIDs = domainObject.Demonstrations.Select(x => x.ID).ToList();
                }

                if (domainObject.GuidanceAbout != null && domainObject.GuidanceAbout.Any())
                {
                    dto.GuidanceAbout = new List<Guid>();
                    foreach (Models.Domain.Fund fund in domainObject.GuidanceAbout)
                    {
                        dto.GuidanceAbout.Add(fund.ID);
                    }
                }

                if (domainObject.ApplicationAbout != null && domainObject.ApplicationAbout.Any())
                {
                    dto.ApplicationAbout = new List<Guid>();
                    foreach (Models.Domain.Fund fund in domainObject.ApplicationAbout)
                    {
                        dto.ApplicationAbout.Add(fund.ID);
                    }
                }

                if (domainObject.Financing != null && domainObject.Financing.Any())
                {
                    dto.Financing = new List<Guid>();
                    foreach (Models.Domain.Fund fund in domainObject.Financing)
                    {
                        dto.Financing.Add(fund.ID);
                    }
                }

                if (domainObject.Roles != null && domainObject.Roles.Any())
                {
                    dto.Roles = new List<Guid>();
                    foreach (Models.Domain.ProjectMeetingRole role in domainObject.Roles)
                    {
                        dto.Roles.Add(role.ID);
                    }
                }

                return dto;
            }
            
            return null;
        }

        #endregion
    }
}

namespace ServiceLibrary.Services.Queries
{
    using System.Collections.Generic;
    using System.Runtime.Serialization;

    using NHibernate;

    using ServiceLibrary.Actioners.Activities;
    using ServiceLibrary.Services.Dto;
    using ServiceLibrary.Services.Results;
    using System;

    /// <summary>
    /// The project meeting query.
    /// </summary>
    [DataContract]
    public class ProjectMeetingQuery : IQuery
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the default fields.
        /// </summary>
        [DataMember]
        public DefaultSearchFields DefaultFields { get; set; }

        /// <summary>
        /// Gets or sets the guid of the project type of the meetings.
        /// </summary>
        [DataMember]
        public Guid? WithProjectType { get; set; }

        /// <summary>
        /// Gets or sets the guid of the demonstration type of the meetings.
        /// </summary>
        [DataMember]
        public Guid? WithDemonstration { get; set; }

        /// <summary>
        /// Gets or sets the guid of the WT role of the meetings.
        /// </summary>
        [DataMember]
        public Guid? WithRole { get; set; }

        /// <summary>
        /// Gets or sets the guid of the location.
        /// </summary>
        [DataMember]
        public Guid? AtLocation { get; set; }

        /// <summary>
        /// Gets or sets the guid of the location.
        /// </summary>
        [DataMember]
        public Enums.ProjectMeetingStatusType? WithStatus { get; set; }

        /// <summary>
        /// Gets or sets the list of profile ids that should be a part of the result.
        /// </summary>
        [DataMember]
        public List<Guid> Profiles { get; set; }

        /// <summary>
        /// Gets or sets whether the profiles are at remote a area.
        /// </summary>
        [DataMember]
        public bool? ProfilesAreAtRemoteArea { get; set; }

        /// <summary>
        /// Gets or sets if it's an entrepreneur.
        /// </summary>
        [DataMember]
        public bool? ProfilesAreEntrepreneur { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <returns>
        /// The <see cref="IResult"/>.
        /// </returns>
        public override IResult Execute(ISession hsession)
        {
            var actioner = new ProjectMeetingActioner(hsession, null);

            return actioner.ExecuteSearchQuery(this);
        }

        #endregion
    }
}

namespace ServiceLibrary.Services.Results
{
    using System.Collections.Generic;
    using System.Runtime.Serialization;

    using ServiceLibrary.Services.Dto;

    /// <summary>
    /// The project meeting result.
    /// </summary>
    [DataContract]
    public class ProjectMeetingResult : IResult
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectMeetingResult"/> class.
        /// </summary>
        public ProjectMeetingResult()
        {
            this.List = new List<ProjectMeeting>();
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the list.
        /// </summary>
        [DataMember]
        public List<ProjectMeeting> List { get; set; }

        /// <summary>
        /// Gets or sets the total row count.
        /// </summary>
        [DataMember]
        public int TotalRowCount { get; set; }

        #endregion
    }
}

namespace ServiceLibrary.Services.Commands
{
    using System;
    using System.Runtime.Serialization;

    using NHibernate;

    using ServiceLibrary.Actioners.Activities;
    using ServiceLibrary.Services.Dto;

    using User = ServiceLibrary.Models.Domain.User;

    /// <summary>
    /// The create project meeting command.
    /// </summary>
    [DataContract]
    public class CreateProjectMeetingCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the project meeting.
        /// </summary>
        [DataMember]
        public ProjectMeeting ProjectMeeting { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new ProjectMeetingActioner(hsession, activeUser);
            actioner.CreateProjectMeeting(this);
        }

        #endregion
    }

    /// <summary>
    /// The update project meeting command.
    /// </summary>
    [DataContract]
    public class UpdateProjectMeetingCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the dto.
        /// </summary>
        [DataMember]
        public ProjectMeeting Dto { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new ProjectMeetingActioner(hsession, activeUser);
            actioner.UpdateProjectMeeting(this);
        }

        #endregion
    }

    /// <summary>
    /// The delete project meeting command.
    /// </summary>
    [DataContract]
    public class DeleteProjectMeetingCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the dto.
        /// </summary>
        [DataMember]
        public Guid? Dto { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new ProjectMeetingActioner(hsession, activeUser);
            actioner.DeleteProjectMeeting(this);
        }

        #endregion
    }
}